﻿using System;

using System.Windows.Forms;

namespace ToolUtil
{
    public partial class FrmPrs : Form
    {
        ProgressHolder holder = null;
        public FrmPrs(ProgressHolder holder, string title)
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterParent;
            this.Text = title;
            this.holder = holder;
        }
        public void SetStatus(string msg)
        {
            if (this.label1.InvokeRequired)
                this.label1.Invoke(new Action<string>(SetStatus), msg);
            else
                this.label1.Text = msg;
        }

        public void SetProgress(int value)
        {
            if (this.progressBar1.InvokeRequired)
                this.label1.Invoke(new Action<int>(SetProgress), value);
            else
                this.progressBar1.Value = value < 0 ? 0 : value > 100 ? 100 : value;

            // if (value == 100) this.Invoke(new Action(this.Hide));

            this.Refresh();
        }
        public void RaiseError(string errorMsg)
        {
            MessageBox.Show(this, errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        public void RaiseInform(string informMsg)
        {
            MessageBox.Show(this, informMsg, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

    }
}
